package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    @RequestMapping("/list")
    private String list(Model model, @ModelAttribute("qo") BannerQuery qo){
       Page<Banner> page = bannerService.query(qo);
       model.addAttribute("page",page);
       return "/banner/list";
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        System.out.println(banner);
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();

    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){

        bannerService.delete(id);

        return  JsonResult.success();
    }
    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){

        Map<String,Object> map = new HashMap();
        List<Strategy> list = strategyService.list();
       map.put("sts",list);
        List<Travel> travelList = travelService.list();
        map.put("ts",travelList);
        return  JsonResult.success(map);
    }
   /* @RequestMapping("/getDestByBannerId")
    @ResponseBody
    public Object getDestByBannerId(String  rid){
        //通过前端传来的id去查找对象集合
       List<Destination> list=  destinationService.queryDtByionId(rid);
            return  list;
    }
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(int hot,String  id){
        //通过前端传来的id去查找对象集合
        bannerService.changeHotValue(hot,id);
            return  JsonResult.success();
    }*/
}
